package com.albaba.springalibabasentinel8085.controller;

import com.albaba.springalibabasentinel8085.exception.CustomerBlockHandle;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: TODO
 * @Author zx
 * @Date 2024/11/22 10:55
 * @Version 1.0
 */
@RestController
public class SentinelResourceController {

    @GetMapping("/byResource")
    @SentinelResource(value = "byResource", blockHandler = "handleException")
    public String byResource() {
        return "按资源名称限流";
    }

    public String handleException(BlockException e) {
        return "系统繁忙";
    }

    @GetMapping("/byUrl")
    @SentinelResource(value = "byUrl")
    public String byUrl() {
        return "按url限流";
    }

    @GetMapping("/byCustomer")
    @SentinelResource(value = "byCustomer",
            blockHandlerClass = CustomerBlockHandle.class,
            blockHandler = "handlerException1")
    public String test() {
        return "test";
    }
}
